{extend name="../../base/view/common/base" /}
{block name="style"}
<style>
html{background-color:#fff;}
.log-timeline{ position: relative; min-height:600px; padding-left: 48px; background-color:#fff;}
.log-timeline:after {content: ""; position: absolute; top: 0; left: 24px; width: 1px; height: 100%; background: #e3e9ed;}
.log-timeline dl{padding-bottom: 8px; position: relative;}
.log-timeline dt{font-size: 16px; line-height: 2.4; color: #323232; font-weight:600}
.log-timeline dd{font-size: 14px; line-height: 1.6; padding:5px 0}
.log-timeline .date-second-point{width: 10px; height: 10px; display: block; border-radius: 50%; border: 3px solid #FBBC05; background: #fff; position: absolute; z-index: 99; left:-32px; top:9px}
.log-timeline .log-thumb{width: 24px; height: 24px; border-radius: 50%; margin-right:4px;}
.log-timeline .open-a{margin:0 4px;}
.log-item i{font-weight:800; color:#323232}
.log-content strong{margin:0 4px; color:#323232}

.check-items{overflow-x: auto; padding: 2px 0;}
.flow-flex-row {box-direction: row;
	box-orient: horizontal;
    -webkit-box-orient: horizontal;
    -ms-flex-direction: row;
    flex-direction: row;
}
.flow-flexbox { width: 100%;text-align: left;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    display: -webkit-flex;
    box-align: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
	flex-wrap: wrap;
}
.check-item{width: auto; -ms-flex-negative: 0; flex-shrink: 0; padding:4px 0}
.check-item i{margin-right:3px; color:#646464;}
.check-item span{color:#999;margin:0 3px;}
.check-item .layui-icon {font-size:18px;}
.check-item .layui-icon.layui-icon-right{font-size:12px;}
.layui-icon[data-ok]{color:#34a853}
.layui-icon[data-no]{color:#FF5722;}
.check-item-status{color:#999; font-size:12px; margin-left:3px;}

.flow-tips{padding:6px 10px;}
.flow-tips li{padding:5px 0;}
.flow-tips li i{color:#4285f4;}
.flow-tips li span{color:#999; font-size:12px; margin-left:4px;}

.flow-record{padding:4px 4px 0;}
.flow-record .layui-timeline-item{text-decoration:line-through; color:#acacac; padding-bottom:10px;}
.flow-record .layui-timeline-item.delete-0{text-decoration:none; color:#323232;}
.layui-timeline-content ul{font-size:12px;}
.check-status{color:#999; margin-left:5px;}
.check-remark{padding:6px; margin-top:6px; margin-bottom:10px; border-radius:4px; background-color:#f5f5f5;}
.check-record{line-height:1.5; padding:4px 0}
.flow-this{font-weight:800;}
.flow-this i{color:#4285f4}
.layui-table-min th{font-size:13px; text-align:center; background-color:#f8f8f8;}
.layui-table-min td{font-size:13px; padding:6px;text-align:center;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form px-4 pt-2" lay-filter="contract">
	<div class="layui-tab" style="margin:0;" lay-filter="contract" id="contractTab">
	  <ul class="layui-tab-title">
		<li class="layui-this" data-load="true">合同详情</li>
		<li>操作记录</li>
	  </ul>
	  <div class="layui-tab-content">
		<div class="layui-tab-item layui-show">	
			<table class="layui-table layui-table-form">
				{gt name="$detail.pid" value="0"}
				 <tr>
					<td class="layui-td-gray">母合同名称</td>
					<td colspan="7">{$detail.pname}</td>
				  </tr>
				{/gt}
			  <tr>
				<td class="layui-td-gray">合同名称</td>
				<td colspan="5">{$detail.name}</td>
				<td class="layui-td-gray">合同编号</td>
				<td>{$detail.code}</td>
			  </tr>
			  <tr>
				<td class="layui-td-gray">签约主体(乙方)</td>
				<td colspan="3">
					{volist name=":contract_subject()" id="v"}
					{eq name="$v.id" value="$detail.subject_id" }{$v.title}{/eq}
					{/volist}
				</td>
				<td class="layui-td-gray">合同性质</td>
				<td>
					{eq name="$detail.type" value="1" }普通合同{/eq}
					{eq name="$detail.type" value="2" }框架合同{/eq}
					{eq name="$detail.type" value="3" }补充协议{/eq}
					{eq name="$detail.type" value="4" }其他合同{/eq}
				</td>
				<td class="layui-td-gray">合同类别</td>
				<td>
					{volist name=":contract_cate()" id="v"}
					{eq name="$v.id" value="$detail.cate_id" }{$v.title}{/eq}
					{/volist}
				</td>
			  </tr>
			  <tr>
				<td class="layui-td-gray">客户名称(甲方)</td>
				<td colspan="3">{$detail.customer}</td>
				<td class="layui-td-gray">签约客户代表</td>
				<td>{$detail.customer_name}</td>
				<td class="layui-td-gray">客户联系电话</td>
				<td>{$detail.customer_mobile}</td>
			  </tr>
			   <tr>
				<td class="layui-td-gray-2">客户联系地址</td>
				<td  colspan="3">{$detail.customer_address}</td>
				<td class="layui-td-gray-2">合同开始日期</td>
				<td>{$detail.start_time}</td>
				<td class="layui-td-gray-2">合同结束日期</td>
				<td>{$detail.end_time}</td>
			  </tr>
			  {neq name="$detail.type" value="2"}
			  <tr>
				<td class="layui-td-gray">合同金额</td>
				<td>{$detail.cost}</td>
				{eq name="$detail.is_tax" value="1" }
				<td class="layui-td-gray">是否含税</td>
				<td>是</td>
				<td class="layui-td-gray">税点(百分比)</td>
				<td colspan="3">{$detail.tax}%</td>
				{/eq}
				{eq name="$detail.is_tax" value="0" }
				<td class="layui-td-gray">是否含税</td>
				<td colspan="5">否</td>
				{/eq}
			  </tr>
			  {/neq}
			  {notempty name="$detail.remark"}
			   <tr>
				<td class="layui-td-gray">备注信息</td>
				<td colspan="7">{$detail.remark}</td>
			  </tr>
			  {/notempty}
				{notempty name="$detail.file_ids"}
				<tr>
					<td class="layui-td-gray">相关附件</td>
					<td colspan="7" style="line-height:inherit">
						<div class="layui-row">
							{volist name="$detail.fileArray" id="vo"}
							<div class="layui-col-md4">
								<div class="file-card">
									<i class="file-icon iconfont icon-renwuguanli"></i>
									<div class="file-title file-title-view">{$vo.name}</div>
									<div class="file-tool">
										<a href="{$vo.filepath}" download="{$vo.name}" target="_blank" title="下载查看"><i class="iconfont icon-shujudaoru blue"></i></a>
									</div>
								</div>
							</div>
							{/volist}
						</div>
					</td>
				</tr>
				{/notempty}			  
			  <tr>
				<td colspan="8"><strong>补充附件</strong></td>
			  </tr>
			  <tr>
				<td class="layui-td-gray">
					<button type="button" class="layui-btn layui-btn-sm" id="uploadBtn"><i class="layui-icon"></i>附件上传</button>
				</td>
				<td colspan="7" style="line-height:inherit">
					<div id="fileBox">
					<input type="hidden" id="fileBoxInput" name="file_ids" value="">
					{volist name="$detail.file_array_other" id="vo"}
					<div class="layui-col-md4" id="fileItem{$vo.id}">
						<div class="file-card">
							<i class="file-icon iconfont icon-renwuguanli"></i>
							<div class="file-title">{$vo.name}</div>
							<div class="file-tool">
								<a href="{$vo.filepath}" download="{$vo.name}" title="下载查看" target="_blank"><i class="iconfont icon-shujudaoru blue"></i></a>
								<i class="ajax-delete iconfont icon-shanchu red" data-id="{$vo.id}" title="删除"></i>
							</div>
						</div>
					</div>
					{/volist}
					</div>
				</td>
			   </tr> 
			  <tr>
				<td colspan="8"><strong>签订信息</strong></td>
			  </tr>
			  <tr>
				<td class="layui-td-gray-2">合同制定人</td>
				<td>{$detail.prepared_name} </td>
				<td class="layui-td-gray-2">合同签订人</td>
				<td>{$detail.sign_name}</td>
				<td class="layui-td-gray-2">合同签订时间</td>
				<td>{$detail.sign_time}</td>
				<td class="layui-td-gray-2">合同签订部门</td>
				<td>{$detail.sign_department}</td>
			  </tr>
			  <tr>        
				<td class="layui-td-gray-2">合同保管人</td>
				<td>{$detail.keeper_name}{gt name="$auth" value="0"}<span id="keeper" data-ids="{$detail.keeper_uid}" data-names="{$detail.keeper_name}" class="layui-btn layui-btn-xs layui-btn-normal ml-1">更改</span>{/gt}</td>
				<td class="layui-td-gray">合同共享人员</td>
				<td colspan="5">{$detail.share_names}{gt name="$auth" value="0"}<span id="shares" data-ids="{$detail.share_ids}" data-names="{$detail.share_names}" class="layui-btn layui-btn-xs layui-btn-normal ml-1">更改</span>{/gt}</td>
			  </tr>	
			  <tr>
				<td colspan="8"><strong>审核信息</strong></td>
			  </tr>
			  <tr>
				<td class="layui-td-gray-2">合同状态</td>
				<td><span class="layui-color-{$detail.check_status}">{$detail.status_name}</span></td>
				<td class="layui-td-gray-2">录入人</td>
				<td>{$detail.admin_name} </td>
				<td class="layui-td-gray-2">录入时间</td>
				<td colspan="3">{$detail.create_time}</td>
			  </tr>		
			{notempty name="$check_record"}
			<tr>
				<td class="layui-td-gray">历史审批记录</td>
				<td colspan="7">
					<ul class="layui-timeline flow-record pt-2">
					{volist name="$check_record" id="vo"}		
						<li class="layui-timeline-item delete-{$vo.delete_time}">
							<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
							<p style="padding-left:24px">{$vo.check_time_str}<span class="black ml-2">{$vo.name}</span><span class="mx-2 layui-color-{$vo.status}">{$vo.status_str}</span>了此申请。操作意见：<span class="green">{$vo.content}</span></p>
						</li>
					{/volist}
					</ul>
				</td>
			</tr>
			{/notempty}
			{eq name="$detail.check_status" value="2" }
			  <tr>
				<td class="layui-td-gray-2">归档状态</td>
				{eq name="$detail.archive_status" value="0" }
				<td colspan="7"><span class="layui-color-{$detail.archive_status}">{$detail.archive_status_name}</span></td>
				{else/}
				<td><span class="layui-color-{$detail.archive_status}">{$detail.archive_status_name}</span></td>
				<td class="layui-td-gray-2">归档人</td>
				<td>{$detail.archive_name} </td>
				<td class="layui-td-gray-2">归档时间</td>
				<td colspan="3">{$detail.archive_time}</td>
				{/eq}
			  </tr>
			{/eq}
			
			{eq name="$detail.check_status" value="4" }
			  <tr>
				<td class="layui-td-gray-2">中止人</td>
				<td>{$detail.stop_name} </td>
				<td class="layui-td-gray-2">中止时间</td>
				<td colspan="5">{$detail.stop_time}</td>
			  </tr>
			  <tr>
				<td class="layui-td-gray-2">中止备注</td>
				<td colspan="7">{$detail.stop_remark}</td>
			  </tr>
			{/eq}
			
			{eq name="$detail.check_status" value="5" }
			  <tr>
				<td class="layui-td-gray-2">作废人</td>
				<td>{$detail.void_name} </td>
				<td class="layui-td-gray-2">作废时间</td>
				<td colspan="5">{$detail.void_time}</td>
			  </tr>
			  <tr>
				<td class="layui-td-gray-2">作废备注</td>
				<td colspan="7">{$detail.void_remark}</td>
			  </tr>
			{/eq}			
			</table>
			
			{eq name="$detail.check_status" value="1" }
				{include file="/index/view_step" /}			
			{/eq}
			<div class="pt-3">
				{gt name="$auth" value="0"}				
					{eq name="$detail.check_status" value="2" }
						{eq name="$detail.archive_status" value="1" }
							<span class="layui-btn layui-btn-danger" data-event="archive" data-status="0">反确认归档</span>
						{else/}
						<span class="layui-btn layui-btn-normal" data-event="archive" data-status="1">合同归档</span>
						<span class="layui-btn layui-btn-danger" data-event="check" data-status="0">反确认审核</span>
						{/eq}
					{/eq}
					{eq name="$detail.check_status" value="5" }
					<div class="py-2">
						<span class="layui-btn layui-btn-danger" data-event="check" data-status="0">反中止合同</span>
					</div>
					{/eq}
					
					{eq name="$detail.check_status" value="6" }
					<div class="py-2">
						<span class="layui-btn layui-btn-danger" data-event="check" data-status="0">反作废合同</span>
					</div>
					{/eq}
				{/gt}	
				{if ( $detail.check_status eq 3) AND ( $is_create_admin eq 1) }
					<span class="layui-btn layui-btn-primary check_back"><i class="layui-icon layui-icon-reduce-circle"></i> 撤回</span>
				{/if}
				{if ( $detail.check_status eq 4) AND ( $is_create_admin eq 1) }
				<a class="layui-btn" href="/finance/invoice/add?id={$detail.id}">重新编辑</a>
				{/if}
			</div>
		</div>
		<div class="layui-tab-item">
			{include file="/index/view_log" /}
		</div>
	  </div>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
const contract_id = '{$detail.id}';
const contract_status = '{$detail.check_status}';
const moduleInit = ['tool','employeepicker','oaTool'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool, upload = layui.upload,element = layui.element,employeepicker = layui.employeepicker,oaTool = layui.oaTool;		
		element.on('tab(contract)', function(data){
			let index = data.index;
			if(index == 1){
				log(layui);	
			}
		});
		
		if (typeof (flowStep) == "function") {
			flowStep();
		}		
	
		//选择合同保管人弹窗	
		$('body').on('click','#keeper',function () {
			var ids=$(this).data('ids')+'',names = $(this).data('names')+'';
			employeepicker.init({
				ids:ids,
				names:names,
				type:0,
				department_url: "/api/index/get_department_tree",
				employee_url: "/api/index/get_employee",
				callback:function(ids,names,dids,departments){
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							location.reload();
						}
					}
					tool.post("/contract/index/add", {'id':contract_id,'keeper_uid':ids,'scene':'change'}, callback);
				}
			});
		});
	
	
		//选择共享成员弹窗	
		$('body').on('click','#shares',function () {
			var  ids=$(this).data('ids')+'',names = $(this).data('names')+'',share_ids_array=[],share_names_array=[];
			if(ids.length>0){
				share_ids_array=ids.split(',');
				share_names_array=names.split(',');
			}
			employeepicker.init({
				ids:share_ids_array,
				names:share_names_array,
				type:1,
				department_url: "/api/index/get_department_tree",
				employee_url: "/api/index/get_employee",
				callback:function(ids,names,dids,departments){
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							location.reload();
						}
					}
					tool.post("/contract/index/add", {'id':contract_id,'share_ids':ids.join(','),'scene':'change'}, callback);
				}
			});
		});
		
		
		$('body').on('click','[data-event="check"]',function(){
			let status = $(this).data('status');
			let action = '';
			let title = ''
			if(contract_status == 2 && status == 0){
				title = '确定要反确认该合同的审核?';
				action = 'check_refue';
			}
			if(contract_status == 5 && status == 0){
				title = '确定要反中止该合同?';
				action = 'stop_no';
			}
			if(contract_status == 6 && status == 0){
				title = '确定要反作废该合同?';
				action = 'void_no';
			}
			layer.confirm(title, {
				icon: 3,
				title: '提示'
			}, function(index) {
				let callback = function (e) {
					layer.msg(e.msg);
					parent.layui.pageTable.reload();
					setTimeout(function(){
						location.reload();
					},2000)					
				}
				tool.post("/contract/api/check", {id: contract_id,check_status:status,mark:''}, callback);			
				layer.close(index);
			});
		});
		
		$('body').on('click','[data-event="archive"]',function(){
			let status = $(this).data('status');
			layer.confirm('合同归档后将不能进行任何数据操作，确定要提交归档?', {
				icon: 3,
				title: '提示'
			}, function(index) {
				let callback = function (e) {
					layer.msg(e.msg);
					parent.layui.pageTable.reload();
					setTimeout(function(){
						location.reload();
					},2000)					
				}
				tool.post("/contract/api/archive", {id: contract_id,archive_status:status}, callback);
				layer.close(index);
			});
		})
		
		
		$('body').on('click','.check_back',function(){
			layer.prompt({
				formType: 2,
				title: '请输入撤回理由',
				area: ['500px', '120px'] //自定义文本域宽高
			}, function(value, index, elem){
				$.ajax({
					url: "/api/index/flow_check",
					type:'post',
					data:{
						id:contract_id,
						type:4,
						check:3,
						content:value
					},
					success: function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {	
							parent.layui.pageTable.reload();
							location.reload();
						}
					}
				})
				layer.close(index);
			});
		})
		
		oaTool.addFile({
			type:1,
			isSave:true,
			ajaxDelete:function(file_id){
				let callback = function (e) {
					layer.msg(e.msg);
					if (e.code == 0) {						
						$('#fileItem' + file_id).remove();
					}
				}
				tool.delete("/contract/api/delete_file", {id: file_id}, callback);			
			},
			ajaxSave:function(res){
				let callback = function (e) {
					location.reload();
				}
				tool.post("/contract/api/add_file", {'contract_id':contract_id,'file_id':res.data.id,'file_name':res.data.name}, callback);
			}
		});
	}

</script>
{/block}
<!-- /脚本 -->